part of 'widget.dart';

class _AppWidgetView extends StatelessWidget {
  _AppWidgetView();

  final _rootRouterDelegate = RootRouterDelegate();

  Widget _wrapWithNestedThemes({
    required Brightness brightness,
    required Color primaryColor,
    required Color primaryContrastingColor,
    required Widget child,
  }) {
    return CoreTheme(
      brightness: brightness,
      primaryColor: primaryColor,
      primaryContrastingColor: primaryContrastingColor,
      child: child,
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      builder: (context, child) {
        const brightness = Brightness.dark;
        const primaryColor = CoreStyles.pink;
        const primaryContrastingColor = Color(0xffffffff);

        return MediaQuery(
          data: MediaQuery.of(context).copyWith(
            textScaleFactor: 1.0,
          ),
          child: NotificationListener<OverscrollIndicatorNotification>(
            onNotification: (OverscrollIndicatorNotification overscroll) {
              overscroll.disallowIndicator();
              return false;
            },
            child: _wrapWithNestedThemes(
              brightness: brightness,
              primaryColor: primaryColor,
              primaryContrastingColor: primaryContrastingColor,
              child: Theme(
                data: ThemeData(
                  brightness: brightness,
                  // TODO: add selected text style here when it gets implemented
                  textSelectionTheme: const TextSelectionThemeData(
                    cursorColor: primaryColor,
                    selectionColor: primaryColor,
                    selectionHandleColor: primaryColor,
                  ),
                  primaryColor: primaryColor,
                ),
                child: CupertinoTheme(
                  data: const CupertinoThemeData(
                    primaryColor: primaryColor,
                    primaryContrastingColor: primaryContrastingColor,
                    brightness: brightness,
                  ),
                  child: Material(
                    child: MultiTouchDisabler(
                      child: RootWidget(child: child!),
                    ),
                  ),
                ),
              ),
            ),
          ),
        );
      },
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      locale: const Locale('en'),
      supportedLocales: const [
        Locale('en'),
      ],
      home: Router(
        routerDelegate: _rootRouterDelegate,
        backButtonDispatcher: RootBackButtonDispatcher(),
      ),
    );
  }
}
